* (bug 9415) Added options to Special:Protect to allow setting of per-page robot
authorRaimond Spekking <raymond@users.mediawiki.org>
Thu, 21 Jun 2007 15:51:28 +0000 (15:51 +0000)
committerRaimond Spekking <raymond@users.mediawiki.org>
Thu, 21 Jun 2007 15:51:28 +0000 (15:51 +0000)
  policies. This can be done only by users with the 'editrobots' permission
  Based on a patch of AmiDaniel

RELEASE-NOTES
includes/Article.php
includes/DefaultSettings.php
includes/ProtectionForm.php
includes/Title.php
languages/messages/MessagesDe.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index d739a00..ca3f8b2 100644 (file)
@@ -95,6 +95,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Throw a showstopper exception when a hook function fails to return a value.
   Forgetting to give a 'true' return value is a very common error which tends
   to cause hard-to-track-down interactions between extensions.
+* (bug 9415) Added options to Special:Protect to allow setting of per-page robot
+  policies. This can be done only by users with the 'editrobots' permission
 
 == Bugfixes since 1.10 ==
 
index ddf5b25..286e97f 100644 (file)
@@ -641,6 +641,8 @@ class Article {
                } elseif( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
                        # Honour customised robot policies for this namespace
                        $policy = $wgNamespaceRobotPolicies[$ns];
+               } elseif ( $this->mTitle->getRestrictions( 'robots' ) ) {
+                       $policy = implode( ',', $this->mTitle->getRestrictions( 'robots' ) );
                } else {
                        # Default to encourage indexing and following links
                        $policy = 'index,follow';
@@ -1675,6 +1677,7 @@ class Article {
                $current = array();
                foreach( $wgRestrictionTypes as $action )
                        $current[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
+               $current['robots'] = implode( '', $this->mTitle->getRestrictions( 'robots' ) );
 
                $current = Article::flattenRestrictions( $current );
                $updated = Article::flattenRestrictions( $limit );
@@ -1710,7 +1713,9 @@ class Article {
                                foreach( $limit as $action => $restrictions ) {
                                        # Check if the group level required to edit also can protect pages
                                        # Otherwise, people who cannot normally protect can "protect" pages via transclusion
-                                       $cascade = ( $cascade && isset($wgGroupPermissions[$restrictions]['protect']) && $wgGroupPermissions[$restrictions]['protect'] );       
+                                       if ( in_array( $restrictions, $wgRestrictionTypes ) ) {
+                                               $cascade = ( $cascade && isset($wgGroupPermissions[$restrictions]['protect']) && $wgGroupPermissions[$restrictions]['protect'] );
+                                       }
                                }
                                
                                $cascade_description = '';
index 6315c4d..2c28d13 100644 (file)
@@ -1063,6 +1063,7 @@ $wgGroupPermissions['sysop']['autoconfirmed']   = true;
 $wgGroupPermissions['sysop']['upload_by_url']   = true;
 $wgGroupPermissions['sysop']['ipblock-exempt'] = true;
 $wgGroupPermissions['sysop']['blockemail']      = true;
+$wgGroupPermissions['sysop']['editrobots']      = true;
 
 // Permission to change users' group assignments
 $wgGroupPermissions['bureaucrat']['userrights'] = true;
index 22533ef..c8bb191 100644 (file)
@@ -43,6 +43,7 @@ class ProtectionForm {
                                // but the db allows multiples separated by commas.
                                $this->mRestrictions[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
                        }
+                       $this->mRestrictions['robots'] = implode( ',', $this->mTitle->getRestrictions( 'robots' ) );
 
                        $this->mCascade = $this->mTitle->areRestrictionsCascading();
 
@@ -72,9 +73,17 @@ class ProtectionForm {
                                        $this->mRestrictions[$action] = $val;
                                }
                        }
+
+                       // Read checkboxex only if user is allowed to change robots policy, otherwise keep previous policy
+                       if ( $wgUser->isAllowed( 'editrobots' ) ) {
+                               $robotspolicy  = $wgRequest->getBool( 'mwProtect-robots-noindex' )  ? 'noindex'   : 'index';
+                               $robotspolicy .= $wgRequest->getBool( 'mwProtect-robots-nofollow' ) ? ',nofollow' : ',follow';
+                               // 'index,follow' is default, no need to set this explicitly at this point; is done at Article::View
+                               $this->mRestrictions['robots'] = ( $robotspolicy == 'index,follow' ) ? '' : $robotspolicy;
+                       }
                }
        }
-       
+
        function execute() {
                global $wgRequest;
                if( $wgRequest->wasPosted() ) {
@@ -199,7 +208,7 @@ class ProtectionForm {
        }
 
        function buildForm() {
-               global $wgUser;
+               global $wgUser, $wgRestrictionTypes;
 
                $out = '';
                if( !$this->disabled ) {
@@ -223,14 +232,17 @@ class ProtectionForm {
                $out .= "<tr>\n";
                foreach( $this->mRestrictions as $action => $required ) {
                        /* Not all languages have V_x <-> N_x relation */
-                       $out .= "<th>" . wfMsgHtml( 'restriction-' . $action ) . "</th>\n";
+                       if ( in_array( $action, $wgRestrictionTypes ) )
+                               $out .= "<th>" . wfMsgHtml( 'restriction-' . $action ) . "</th>\n";
                }
                $out .= "</tr>\n";
                $out .= "<tr>\n";
                foreach( $this->mRestrictions as $action => $selected ) {
-                       $out .= "<td>\n";
-                       $out .= $this->buildSelector( $action, $selected );
-                       $out .= "</td>\n";
+                       if ( in_array( $action, $wgRestrictionTypes ) ) {
+                               $out .= "<td>\n";
+                               $out .= $this->buildSelector( $action, $selected );
+                               $out .= "</td>\n";
+                       }
                }
                $out .= "</tr>\n";
 
@@ -249,6 +261,7 @@ class ProtectionForm {
                if( !$this->disabled )
                        $out .= '<tr><td></td><td>' . $this->buildWatchInput() . "</td></tr>\n";
 
+               $out .= $this->buildRobotsInput();
                $out .= $this->buildExpiryInput();
 
                if( !$this->disabled ) {
@@ -317,6 +330,20 @@ class ProtectionForm {
                return $ci;
        }
 
+       function buildRobotsInput() {
+               global $wgUser;
+               $robotsallowed = $wgUser->isAllowed( 'editrobots' ) ? array() : array( 'disabled' => 'disabled' );
+               $noindexset  = ( isset( $this->mRestrictions['robots'] ) && strstr( $this->mRestrictions['robots'], 'noindex' ) )  ? true : false;
+               $nofollowset = ( isset( $this->mRestrictions['robots'] ) && strstr( $this->mRestrictions['robots'], 'nofollow' ) ) ? true : false;
+               $ret = "<tr><td align=\"right\">";
+               $ret .= Xml::label( wfMsg( 'protect-robotspolicy' ), 'mwProtect-robots-label' );
+               $ret .= "</td> <td align=\"left\" width=\"60\">";
+               $ret .= Xml::checkLabel( 'noindex', 'mwProtect-robots-noindex', 'mwProtect-robots-noindex', $noindexset, $robotsallowed );
+               $ret .= Xml::checkLabel( 'nofollow', 'mwProtect-robots-nofollow', 'mwProtect-robots-nofollow', $nofollowset, $robotsallowed );
+               $ret .= "</td></tr>";
+               return $ret;
+       }
+
        function buildExpiryInput() {
                $attribs = array( 'id' => 'expires' ) + $this->disabledAttrib;
                return '<tr>'
index 8a21ab3..b875f85 100644 (file)
@@ -940,6 +940,9 @@ class Title {
                if( $this->getNamespace() == NS_SPECIAL )
                        return true;
 
+               if ( $this->getRestrictions( 'robots' ) && $this->getRestrictions( 'robots' ) != '' ) 
+                       return true;
+
                # Check regular protection levels                               
                if( $action == 'edit' || $action == '' ) {
                        $r = $this->getRestrictions( 'edit' );
index b0846a6..ab20739 100644 (file)
@@ -1442,6 +1442,7 @@ Bitte gehen Sie zurück und versuchen den Vorgang erneut auszuführen.',
 'protect-summary-cascade'     => 'kaskadierend',
 'protect-expiring'            => 'bis $1 (UTC)',
 'protect-cascade'             => 'Kaskadierende Sperre – alle in diese Seite eingebundenen Vorlagen werden ebenfalls gesperrt.',
+'protect-robotspolicy'        => 'Anweisung für Suchroboter:',
 'restriction-type'            => 'Schutzstatus',
 'restriction-level'           => 'Schutzhöhe',
 'minimum-size'                => 'Mindestgröße:',
index c25e3cf..984554a 100644 (file)
@@ -1839,6 +1839,7 @@ Here are the current settings for the page <strong>$1</strong>:',
 'protect-summary-cascade'     => 'cascading',
 'protect-expiring'            => 'expires $1 (UTC)',
 'protect-cascade'             => 'Protect pages included in this page (cascading protection)',
+'protect-robotspolicy'        => 'Robot policy:',
 'restriction-type'            => 'Permission:',
 'restriction-level'           => 'Restriction level:',
 'minimum-size'                => 'Min size',
index 0707ba2..8c9c74f 100644 (file)
@@ -1182,6 +1182,7 @@ $wgMessageStructure = array(
                'protect-summary-cascade',
                'protect-expiring',
                'protect-cascade',
+               'protect-robotspolicy',
                'restriction-type',
                'restriction-level',
                'minimum-size',